package gui;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import util.Protocol;
import net.BackClient;
import net.ReceiveInformation;

public class AddFriendUI extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	BackClient backClient = new BackClient();
	Protocol protocol = new Protocol();
	ReceiveInformation information = new ReceiveInformation();
	Thread thread = new Thread(new ReceiveInformation());
	String nickname;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AddFriendUI frame = new AddFriendUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public AddFriendUI() {
		thread.start();
		information.addthisWindows("addFriendUI", this);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 355, 210);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("\u597D\u53CB\u6DFB\u52A0");
		label.setFont(new Font("宋体", Font.BOLD, 15));
		label.setBounds(141, 10, 128, 15);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("\u597D\u53CB\u6635\u79F0\uFF1A");
		label_1.setBounds(81, 84, 73, 15);
		contentPane.add(label_1);
		
		textField = new JTextField();
		textField.setBounds(141, 81, 103, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JButton okButton = new JButton("\u786E\u5B9A");
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String friendID = textField.getText();
				String finalmessgae = protocol.getAddFriendMessage(nickname,friendID);
				backClient.SendMassage(finalmessgae);
			}
		});
		okButton.setBounds(264, 79, 73, 25);
		contentPane.add(okButton);
		
		JButton backbutton = new JButton("\u8FD4\u56DE");
		backbutton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		backbutton.setBounds(10, 148, 73, 25);
		contentPane.add(backbutton);
	}
	
	public void getNickname(String nickname)
	{
		this.nickname = nickname;
	}
}

